<?php

namespace App\Http\Controllers\Admin;

use App\Http\Models\Auth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Response;

class AuthController extends Controller
{
    public function add(Request $request)
    {
        if($request->isMethod('POST')){
            // 入库
            $data = $request->only(['name', 'show_name']); // 接收
            $status = Auth::create($data);// 插入模型对象
            if($status){
                // ajax提供
                return Response::json([
                    'status' => 'success',
                    'code' => 1000,
                    'msg' => '权限添加成功！'
                ]);

            }else{
                return Response::json([
                    'status' => 'failure',
                    'code' => 1002,
                    'msg' => '权限添加失败！'
                ]);
            }
        }

        return view('admin.auth.add');
    }
    public function lst()
    {
        // 权限
        $size = 2;
        $authData = Auth::paginate($size);
        return view('admin.auth.lst', compact('authData'));
    }
}
